﻿using HY.DataAchieve;
using HY.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HY.Service
{
    public class RentService : BaseService
    {
        /// <summary>
        /// 新增租赁
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int RentAdd(RentDetail model)
        {
            using (UnitOfWork unit = new UnitOfWork())
            {
                unit.BeginTransaction();
                unit.Dapper().Execute("UPDATE Location SET IsRented=1,RentDeptID=@RentDeptID WHERE ID=@ID", new { ID = model.LocationID, RentDeptID=model.RentDeptID });
                unit.EF<RentDetail>().Add(model);
                return unit.Commit();
            }
        }
        /// <summary>
        /// 结束租赁
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int RentClose(RentDetail model)
        {
            using (UnitOfWork unit = new UnitOfWork())
            {
                unit.BeginTransaction();
                unit.Dapper().Execute("UPDATE Location SET IsRented=0,RentDeptID=0 WHERE ID=@ID", new { ID = model.LocationID });
                unit.EF<RentDetail>().Update(model);
                return unit.Commit();
            }
        }
    }
}
